-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repl: add repl.setupHistory for programmatic repl #25895
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from not having documentation yet, this LGTM and I'm 👍 on having the feature
Adds a `repl.setupHistory()` instance method so that programmatic REPLs can also write history to a file. This change also refactors all of the history file management to `lib/internal/repl/history.js`, cleaning up and simplifying `lib/internal/repl.js`.
059a3ec
to
bef8550
Compare
246c015
to
3352e6e
Compare
Final CI after latest commits: https://ci.nodejs.org/job/node-test-pull-request/20728/ |
Adds a `repl.setupHistory()` instance method so that programmatic REPLs can also write history to a file. This change also refactors all of the history file management to `lib/internal/repl/history.js`, cleaning up and simplifying `lib/internal/repl.js`. PR-URL: #25895 Reviewed-By: Daniel Bevenius <[email protected]>
Landed in: 0aa7444 |
Adds a `repl.setupHistory()` instance method so that programmatic REPLs can also write history to a file. This change also refactors all of the history file management to `lib/internal/repl/history.js`, cleaning up and simplifying `lib/internal/repl.js`. PR-URL: #25895 Reviewed-By: Daniel Bevenius <[email protected]>
It looks like this feature was added while not adhering to the XDG basedir spec? What steps are necessary to get XDG adopted as a requirement for future features? It's rather frustrating as a user to see progress made (npm's config location configurable via env var, node-gyp) only to backslide whenever node writes a new file somewhere. #2224 (comment) The problematic line: 0aa7444#diff-8b3e69eaa9660fb13cfc197d34eafbfbR33 |
@jasonkarns that line wasn't added, just moved from here. It was added four years ago in this commit. I think if you want the |
Prior to this PR, Now |
A potential (untested) fix would be to have this line respect |
@jasonkarns I am not really following here, sorry. When invoking The only thing this pull request did to change behavior is to allow users of a repl.setupHistory(env.NODE_REPL_HISTORY, cb); |
The user of the repl API will be cli module authors. The users who have files written to their home directory will be users of those modules. Sure, nothing stops the module authors from being good citizens. But I think the repl API would be more friendly to the final end users if being a good citizen were opt-OUT instead opt-IN. If the repl API is going to provide a default value at all (which it presently does), then I strongly think that default value should respect end user configuration. That way, module authors are "good citizens" by default, instead of "bad citizens" by default. |
@jasonkarns bear with me for a moment please. I really don't understand what problem you are trying to solve. If I add a check here for As a cli module author, it would seem odd to me that if I wanted output to be written to the If |
Agree.
Agree that it's not obvious. But as a module author, if I were reading the code at face value without observing the history, it would seem to me that it's an intentional behavior (albeit undocumented). Otherwise, why would there be a default fallback for falsy, non-string at all? I'm sure you've encountered numerous other weird APIs in your history where passing in So while it may not be documented, or even likely, Hyrum's Law applies:
So I'm suggesting that, for as long as it's even possible for the Or alternatively, I guess, eliminate the default behavior entirely from the public method [1]. But I would much prefer the former; since that could pave the way for a potential future documented way for module authors to fallback to defaults (in an end-user-friendly way). [1] AFAICT, the falsy fallback really only exists to satisfy (Sorry, as the discussion grows, I probably should have opened a separate issue that could facilitate a corresponding PR. Should I still?) Also, I apologize for my initial tone as it bore out some general frustration with so many utilities and whatnot continuing to ignore/be-unaware-of/violate the XDG spec. Thanks for the new repl history feature in the first place. 🙇 ❤️ |
Yes, I think this would be best. I would definitely like more eyes on it, since I am generally -0 on your suggested change. I have a local change with a test that fits the bill, but I do not want to push it until a wider discussion occurs.
No worries. :) |
Adds a
repl.setupHistory()
instance method so that programmatic REPLs can also write history to a file without the need to implement this functionality in userland.This change also refactors all of the history file management to
lib/internal/repl/history.js
, cleaning up and simplifyinglib/internal/repl.js
.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesThis has been done and rejected in the past in #5789. The PR was rejected due to a desire to keep the surface area of the REPL API small. However, there have been additional requests to have this issue reopened here, and I thought I'd give it another go.
If there is consensus on moving forward with this, I will add documentation.
If, ultimately, we decide not to merge this, I think the refactoring of the history file functionality into
lib/internal/repl/history.js
is worthwhile, makes the code easier to read, and does not change the API.EDIT documentation has been added to
repl.md
. I'm not sure what to put for the version number in the documentation YAML. I've made it v11.9.1, but not sure if this just gets modified when landing. I couldn't find anything in the collaborator's guide which addresses this issue.